// 新增页面子表编辑后事件


import deepCopy from '../../../../../public/functions/deep-copy';
import afterEditTable from '../request/afterEditTable';

import {
    toast
} from 'nc-lightapp-front';

export default async function(...args) {

    let [, tableId, key, , changedrows, index, , , , , , , ,func_type = 1] = args;

    const {
        cardTable: {
            getAllRows,
            setTableData
        },
        humanResourceOrganizationValue: {
            refpk
        }
    } = this.props;

    let allTableData = deepCopy(getAllRows(tableId));

    let postData = {
        areaCode: tableId,
        func_type: func_type,
        key: key,
        model: {
            areaCode: tableId,
            rows: [allTableData[index]]
        },
        oldValue: changedrows[0].oldvalue.value,
        pk_org: refpk,
        //下面两个参数只在试用子集修改是有用其他子集暂时没用
        rowCount: allTableData.length,
        rowIndex: index
    };

    try {
        let res = await afterEditTable(postData);
        
        // 拿到该行设置的值
        if(res.data.gridData[tableId]) {
            allTableData[index] = res.data.gridData[tableId].rows[0];
            setTableData(tableId, {
                rows: allTableData
            });
        }
        // 如果有错误消息
        if(res.data.errMsg) {
            toast({
                color: 'danger',
                content: res.data.errMsg
            });
        }
        // 没有处理disableditem
    }
    catch(e) {
    }
    


}
